﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Snake2
{
    class Drawer
    {
        public Drawer()
        {
            Console.CursorVisible = false;
        }

        public void DrawObjectList(IEnumerable<ConsoleSnake> nodes)
        {
            foreach (var consoleNode in nodes)
            {
                DrawObject(consoleNode);
            }
        }

        public void DrawObject(ConsoleSnake obj)
        {
            Console.ForegroundColor = obj.NodeColor;
            Console.SetCursorPosition(obj.X, obj.Y);
            Console.Write(obj.NodeSymbol);
        }

        public void DrawGameField(GameField field, char symbol)
        {
            int frameX = field.X - 1;
            int frameY = field.Y - 1;
            int frameHeight = field.Height + 2;
            int frameWidth = field.Width + 2;

            for (int i = 0; i < frameHeight; i++)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.SetCursorPosition(frameX, frameY + i);
                for (int j = 0; j < frameWidth; j++)
                {
                    if (i == 0 || i == frameHeight - 1)
                        Console.Write(symbol);
                    else if (j == 0 || j == frameWidth - 1)
                        Console.Write(symbol);
                    else Console.Write(" ");

                }
                Console.WriteLine("\n");
            }
        }

        public void DrawScoreAndMessage(GameField field, string message, int score, int speed)
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.SetCursorPosition(field.X + field.Width + 5, field.Y - 1);
            Console.Write("Score: {0}", score);
            Console.SetCursorPosition(field.X + field.Width + 5, field.Y + 1);
            Console.Write("Speed: {0}", speed);
            Console.SetCursorPosition(field.X + field.Width + 5, field.Y + 3);
            Console.Write(message);

        }
    }
}
